package org.llw.ldailytask.util;

import org.llw.ldailytask.R;
import org.llw.ldailytask.entity.Item;
import org.llw.ldailytask.entity.Task;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MySpinnerAdapter extends BaseAdapter {
	
	private Context context;
	private Item[] data;
	
	public MySpinnerAdapter(Context context, Item[] date) {
		this.context=context;
		this.data=date;
	}

	@Override
	public int getCount() {
		return data.length;
	}

	@Override
	public Object getItem(int i) {
		return data[i];
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater layoutInflater=LayoutInflater.from(context);
        convertView=layoutInflater.inflate(R.layout.spinner_item,null);
        if(convertView!=null) {
            ImageView imageView = (ImageView)convertView.findViewById(R.id.img_item);
            imageView.setImageResource(data[position].getIconID());
            TextView textView=(TextView)convertView.findViewById(R.id.txt_item);
            textView.setText(data[position].getStr());
        }
		return convertView;
	}

}
